package com.gisuni.sddc.platformManager.controller;

import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.json.JSONObject;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.GET;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.POST;
import org.nutz.mvc.annotation.Param;

import com.gisuni.sddc.platformManager.model.Response;
import com.gisuni.sddc.platformManager.service.ProjectDetailService;
import com.gisuni.sddc.platformManager.service.ProjectRTypeDetailService;
import com.gisuni.sddc.util.StringUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 项目(中长期/短期/扩展等)明细表操作
* Title: 
* Description: 
* @author landa
* @date 2017年4月26日 下午5:57:57
 */
@IocBean(singleton = false)
@At("/client/service/ProjectDetailController")
public class ProjectDetailController{

	private Log log = Logs.getLog(ProjectDetailController.class);
 
	@Inject
    private ProjectDetailService projectDetailService;

 
	/**
	 * 获取项目的字段信息
	 * @param projectName
	 * @param projectType
	 * @param page
	 * @param rows
	 * @param request
	 * @return
	 */
	@At("/getColumnInfo")
	@GET
	@POST
	@Ok("raw:json") 
    public Object getColumnInfo(@Param("table") String table ,HttpServletRequest request) {
		Response res = new Response();
		res.setSuccess(false);
		Object r = res;
		try {
			Object object= projectDetailService.getColumnInfo(table);
			res.setResult(object);
			r = Response.toJSONObject(res);
		} catch (Exception e) {
			log.error(e.getMessage());
			res.setMsg(e.getMessage());
			return res;
		}
		return r;
    }
 
    
	/**
	 * 获取项目明细数据
	 * @param request
	 * @return
	 */
	@At("/getProjectData")
	@GET
	@POST
	@Ok("json")
    public Object getProjectDetailData(@Param("table") String table,@Param("pkUUid") String pkUUid,HttpServletRequest request) {
		Response res = new Response();
		res.setSuccess(false);
		Object r = res;
		try {
			res = projectDetailService.getProjectDetailData(table,pkUUid); 
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		return res;
    }
	
    
	/**
	 * 新增/编辑项目明细数据
	 * @param request
	 * @return
	 */
	@At("/addOrEdit")
	@GET
	@POST
	@Ok("json")
    public Object editProject(HttpServletRequest request) {
		Response res = new Response();
		res.setSuccess(false);
		Object r = res;
		try {
			res = projectDetailService.editProject(request); 
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		return res;
    }

 
	
 
	/**
	 * 删除
	 * @param request
	 * @return
	 */
	@At("/delete")
	@GET
	@POST
	@Ok("json")
    public Object delete(HttpServletRequest request) {
		Response res = new Response();
		res.setSuccess(false);
		boolean r=false;
		try {
			res = projectDetailService.deleteProject(request); 
              if(r==true){
            	  res.setSuccess(true);  
              }
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		return res;
    }
	
 
}
